import bpy

from 节点.全局控制.Node.节点和插座基类 import bl_节点基类

import Core.bl_UI配色 as UI配色

import engine.initLIB.load_dll as engineLib
import ctypes



engineLib.flexCAPI.f_创建拷贝数据节点.restype = ctypes.c_bool
engineLib.flexCAPI.f_创建合并数据节点.restype = ctypes.c_bool







class C_Node_拷贝数据(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_拷贝数据'
	bl_label = '拷贝数据'

	def init(self, context):
		super(C_Node_拷贝数据, self).f_init(context)
		self.inputs.new('C_NodeSocket_动态插座', name='源')
		self.inputs.new('C_Socket_UI32', name='数量')
		self.outputs.new('C_NodeSocket_动态插座', name='data')
		
		self.f_toCPP(self.id_data)
		
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建拷贝数据节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			self.inputs['数量'].f_update()
			self.use_custom_color = True
			self.color = UI配色.g_容器操作类节点颜色
			

	
class C_NODE_MENU_拷贝数据(bpy.types.Operator):
	bl_idname = 'node.global_node_copy_data'
	bl_label = '拷贝数据'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_拷贝数据', use_transform=True)
		return {'FINISHED'}
		











class C_Node_合并数据(bl_节点基类.C_Node_基类):
	bl_dname = 'bl_node_合并数据'
	bl_label = '合并数据'

	def init(self, context):
		super(C_Node_合并数据, self).f_init(context)
		self.inputs.new('C_Socket_引用', name='源A')
		self.inputs.new('C_Socket_引用', name='源_2')
		self.outputs.new('C_NodeSocket_动态插座', name='data')
		
		self.f_toCPP(self.id_data)
		
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建合并数据节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			bl_节点基类.f_重新调整节点插座(self, False)
			
			self.use_custom_color = True
			self.color = UI配色.g_容器操作类节点颜色

		for s in self.inputs:
			print('C_Node_合并数据 = s = ', s.identifier, s.name)

	def update(self):
		print('engineLib.flexCAPI.f_node_节点是否存在() = ', engineLib.flexCAPI.f_node_节点是否存在())
		if engineLib.flexCAPI.f_node_节点是否存在(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name)) :
			bl_节点基类.f_input插座动态增减(self, 2, 'C_Socket_引用', "源")
		super(C_Node_合并数据, self).update()
		
		#pass
class C_NODE_MENU_合并数据(bpy.types.Operator):
	bl_idname = 'node.global_node_merge_data'
	bl_label = '合并数据'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_合并数据', use_transform=True)
		return {'FINISHED'}
		









classes = (
	C_Node_拷贝数据,
	C_NODE_MENU_拷贝数据,

	C_Node_合并数据,
	C_NODE_MENU_合并数据,
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)















